<?php defined('SYSPATH') or die('No direct access allowed.');

class Model_Product_Profit extends ORM
{
    public static function get_product_profit($type_id, $params)
    {
        switch ($type_id) {
            case 1:
                $suitid = DB::select('suitid')
                    ->from('line_suit_price')
                    ->where('lineid','=',$params['id'])
                    ->and_where('adultprice','>',0)
                    ->and_where('day','>',strtotime(date('Y-m-d',time())))
                    ->execute()
                    ->get('suitid');
                $profit=Model_Line::get_profit($params['id']);
                break;
            case 2:
                $suitid = DB::select('suitid')
                    ->from('hotel_room_price')
                    ->where('hotelid','=',$params['id'])
                    ->and_where('price','>',0)
                    ->and_where('day','>',strtotime(date('Y-m-d',time())))
                    ->execute()
                    ->get('suitid');
                $profit=Model_Hotel::get_profit($params['id']);
                break;
            case 3:
                $suitid = DB::select('suitid')
                    ->from('car_suit_price')
                    ->where('carid','=',$params['id'])
                    ->and_where('adultprice','>',0)
                    ->and_where('day','>',strtotime(date('Y-m-d',time())))
                    ->execute()
                    ->get('suitid');
                $profit=Model_Car::get_profit($params['id']);
                break;
            case 5:
                $suitid = DB::select('ticketid')
                    ->from('spot_ticket_price')
                    ->where('spotid','=',$params['id'])
                    ->and_where('adultprice','>',0)
                    ->and_where('day','>',strtotime(date('Y-m-d',time())))
                    ->execute()
                    ->get('ticketid');
                $profit=Model_Spot::get_profit($params['id']);
                break;
            case 13:
                $suitid = 0;
                $profit=Model_Tuan::get_profit($params['id']);
                break;
            case 21:
                $suitid = DB::select('id')
                    ->from('malls_suit')
                    ->where('productid','=',$params['id'])
                    ->and_where('price','>',0)
                    ->execute()
                    ->get('id');
                $profit=Model_Malls::get_profit($params['id']);
                break;
            case 23:
                $suitid = 0;
                $profit = Model_Combination::get_profit($params['id']);
                break;
            case 104:
                $suitid = 0;
                $profit = Model_Ship::get_profit($params['id']);
                break;
            case 114:
                $suitid = DB::select('suitid')
                    ->from('outdoor_suit_price')
                    ->where('outdoorid','=',$params['id'])
                    ->and_where('price','>',0)
                    ->and_where('day','>',strtotime(date('Y-m-d',time())))
                    ->execute()
                    ->get('suitid');
                $profit=Model_Outdoor::get_profit($params['id']);
                break;
            case 118:
                $suitid = DB::select('id')
                    ->from('techan_suit')
                    ->where('productid','=',$params['id'])
                    ->and_where('price','>',0)
                    ->execute()
                    ->get('id');
                $profit=Model_Techan::get_profit($params['id']);
                break;
            case 121:
                $suitid = DB::select('id')
                    ->from('food_suit')
                    ->where('productid','=',$params['id'])
                    ->and_where('price','>',0)
                    ->execute()
                    ->get('id');
                $profit=Model_Food::get_profit($params['id']);
                break;
            default:
                $suitid = DB::select('suitid')
                    ->from('model_suit_price')
                    ->where('productid','=',$params['id'])
                    ->and_where('price','>',0)
                    ->and_where('day','>',strtotime(date('Y-m-d',time())))
                    ->execute()
                    ->get('suitid');
                $profit=DB::select('profit')
                    ->from('model_suit_price')
                    ->where('productid','=',$params['id'])
                    ->and_where('profit','>',0)
                    ->and_where('day','>',strtotime(date('Y-m-d',time())))
                    ->execute()
                    ->get('profit');
                break;
        }
        return [$profit,$suitid];
    }
}
